package com.atguigu.gmall.publisher.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.publisher.bean.DetailStats;
import com.atguigu.gmall.publisher.bean.NameValue;
import com.atguigu.gmall.publisher.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderController {


    @Autowired
    OrderService orderService;

    @GetMapping("statsByItem")
    public  String statsByItem(@RequestParam("itemName") String itemName,
                               @RequestParam("date") String date,
                               @RequestParam("t") String type){
        List<NameValue> nameValueList = orderService.statsByItem(itemName, date, type);

       return  JSON.toJSONString(nameValueList);
    }
    @GetMapping("/detailByItem")
    public String detailByItem(@RequestParam("itemName") String itemName,
                               @RequestParam("date") String date,
                               @RequestParam("pageNo") Integer pageNo,
                               @RequestParam("pageSize")Integer pageSize){

        DetailStats detailStats = orderService.detailByItem(itemName, date, pageNo, pageSize);
        return   JSON.toJSONString(detailStats);
    }
}
